#include <bits/stdc++.h>

using namespace std;
class Solution {
   public:
    int addDigits(int num) {
        vector<int> v;
        int ret = 10;
        while (ret < 10){
            while (num){
                ret += num % 10;
                num /= 10;
            }
            num = ret;
        }
        return ret;
    }
};

int main(){
    Solution s;
    cout << s.addDigits(38) << endl;
}